
//
// Copyright 2009 Arne Halvorsen (arne.halvorsen@gmail.com)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Project page: http://code.google.com/p/mf4j/

//
// 091116 - aha42 - Starts in line change tracking.
// 091121 - aha42 - Added project page link (google code) to header comment.
// 091210 - aha42 - IOException -> FlickrException.
//

package org.aha.mf4j.reflection;

import org.aha.mf4j.FlickrException;
import org.aha.mf4j.response.FlickrObject;

/**
 * <p>
 *   Represents a Flickr method argument meta data.
 * </p>
 * @author Arne Halvorsen (aha42)
 */
public final class FlickrArgument 
{
  private final String m_name;
  
  private final boolean m_optional;
  
  private final String m_desc;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param argumentFo {@link FlickrObject} of type {@code argument} to
   *                   construct from.
   * @throws FlickrException If fails.
   */
  public FlickrArgument(FlickrObject argumentFo) throws FlickrException
  {
    if (argumentFo==null)
    {
      throw new NullPointerException("fo");
    }
    
    argumentFo.assertType("argument");
    
    m_name=argumentFo.getMandatoryAttribute("name");
    
    String optional=argumentFo.getMandatoryAttribute("optional");
    m_optional=optional.equals("1");
    
    m_desc=argumentFo.getValue();
  }
  
  /**
   * <p>
   *   Gets argument name.
   * </p>
   * @return Name.
   */
  public String getName(){ return m_name; }
  
  /**
   * <p>
   *   Tells if argument is optional.
   * </p>
   * @return {@code true} if is, {@code false} if is not.
   */
  public boolean getIsOptional(){ return m_optional; }
  
  /**
   * <p>
   *   Gets description of argument.
   * </p>
   * @return Argument or {@code null} if has none.
   */
  public String getDescription(){ return m_desc; }
  
  @Override
  public String toString() 
  {
    StringBuilder sb=new StringBuilder();
    
    sb.append("name=").append(m_name).append(",optional=").append(m_optional);
      
    if (m_desc!=null) sb.append(",description=").append(m_desc);
    
    return sb.toString();
  }
  
  /**
   * <p>
   *   The empty array shared.
   * </p>
   */
  public static final FlickrArgument[] E_ARRAY=new FlickrArgument[0];
  
}
